<?php
class Admin_GroupController extends Zend_Controller_Action{
	public function init(){
		$this->_sess = new Zend_Session_Namespace();
   		if(!@$this->_sess->id){
			$this->_helper->redirector('index','login','admin');
		}
	}
	public function indexAction(){
		$mode = new Admin_Model_Group;
		$data = $mode->show_group();
		$this->view->show_group = $data;
	}
	
	public function addAction(){
		$mode = new Admin_Model_Group;
		if($this->_request->isPost()){
			$data=$this->getRequest()->getPost();
			unset($data['sub']);
			$data = $mode->insert_group($data);
		}
		$form = new Admin_Form_Addgroup;
		$this->view->form = $form;
	}
	public function deleteAction(){
		$mode = new Admin_Model_Group;
		$id = $this->getRequest()->getParam('id');
		if($id){
			$mode->delete_group_user($id);
		}
		$this->_helper->redirector('');
	}
	
	public function editAction(){
		$mode = new Admin_Model_Group;
		$id = $this->getRequest()->getParam('id');
		if($this->_request->getPost()){
			$data=$this->getRequest()->getPost();
			unset($data['sub']);
			$mode->update_group($id,$data);
		}
		$form = new Admin_Form_Editgroup;
		$edit = $form->edit($id);
		$this->view->form = $edit;
	}
}